import hashlib
from django.conf import settings
import uuid

""" 对密码进行加密处理"""


def str_to_md5(string):
    # 给 MD5 加盐
    md5_obj = hashlib.md5(settings.SECRET_KEY.encode('utf-8'))
    md5_obj.update(string.encode('utf-8'))
    res = md5_obj.hexdigest()
    return res


# 生成随机字符串
def str_add_uid(string):
    """给上传的图片名命"""
    name = uuid.uuid4()
    res = '%s-%s' % (str(name), string)
    return str_to_md5(res)
